package com.rp.api.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ 配置类
 */
@Configuration
public class RabbitMQConfig {


    /**
     * 定义交换机的名字
     */
    public static final String EXCHANGER_ARTICLE = "exchanger_article";


    /**
     * 定义队列的名字
     */
    public static final String QUEUE_DOWNLOAD_HTML = "queue_download_html";
    public static final String QUEUE_DOWNLOAD_HTML_TEST = "queue_download_html_test";


    //创建交换机
    @Bean
    public Exchange articleExchange(){
        return ExchangeBuilder.topicExchange(EXCHANGER_ARTICLE).durable(true).build();
    }

    //创建队列
    @Bean
    public Queue articleQueue(){
        return new Queue(QUEUE_DOWNLOAD_HTML);
    }


    //创建队列
    @Bean
    public Queue articlehtmlQueue(){
        return new Queue(QUEUE_DOWNLOAD_HTML_TEST);
    }

    //给队列绑定交换机
    public Binding articleBinding(){
        return BindingBuilder
                .bind(articleQueue())
                .to(articleExchange())
                .with("article.*")
                .noargs();
    }

    //给队列绑定交换机
    public Binding articlehtmlBinding(){
        return BindingBuilder
                .bind(articlehtmlQueue())
                .to(articleExchange())
                .with("article.*.*")
                .noargs();
    }


}
